{include file="public/head"/}
<div class="layui-fluid" id="LAY-app-message">
    <div class="layui-card">
        <div class="layui-card-header">广告位列表</div>
        <div class="layui-card-body">
            <table class="layui-table" id="list" lay-filter="list"></table>
        </div>
    </div>
</div>
{include file="public/foot"/}
<script type="text/html" id="url">
    <a href="{{d.url}}" target="_blank">{{d.url}}</a>
</script>
<script type="text/html" id="open">
    <input type="checkbox" name="open" value="{{d.id}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="open" {{ d.open == 1 ? 'checked' : '' }}>
</script>
<script type="text/html" id="action">
    <a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
</script>
<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon layui-icon-add-1"></i>添加广告位</button>
    </div>
</script>
<script>
    layui.config({
        base: '__LAYDMIN__',{if config('app.app_debug')}version: true{/if}
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','table','form'],function(){
				var $ = layui.$, admin = layui.admin, table = layui.table, element = layui.element, form = layui.form,util = layui.util, upload = layui.upload;
				var tableLoadDiv = window.top.layer.load(0,{shade:[0.15, '#000']}); //加载层,table.render完成时需要关闭
				//列表渲染			
				tableIn = table.render({
					elem: '#list',
					url: '{:url(SYS_PATH.'/'.CONTROLLER.'/index')}',
					toolbar: '#toolbar',
					method: 'post',
					cols: [[
						{checkbox: true, fixed: true},
						{field: 'ad_postion_id', title: 'ID', width: 50, fixed: true},
						{field: 'name', title: '广告位名称', width: 400,templet: '#title'},
						{field: 'create_time', title: '添加时间',width: 180,templet: function(d){
							return util.toDateString(d.create_time*1000,'yyyy-MM-dd HH:mm:ss');
						}},
						{field: 'sort', align: 'center', title: '排序', width: 80, edit:'text'},
						{width: 160, align: 'center', toolbar: '#action'}
					]],
					done:function (res) {   //返回数据执行回调函数
						window.top.layer.close(tableLoadDiv);    //返回数据关闭loading
					}						
				});
				
				//头工具栏事件
				table.on('toolbar(list)', function(obj){
					switch(obj.event){
						case 'add':
							layui.layerOpen("{:url(SYS_PATH.'/'.CONTROLLER.'/add')}","添加广告位");
							break;
						case 'direct':
							layui.deleteAll("{:url(SYS_PATH.'/'.CONTROLLER.'/doDeleteAll')}","确定要批量删除广告位吗？",tableIn);//tableIn为渲染列表对象
							break;
					}
				});		
				
				//列表编缉与删除---监听工具条
				table.on('tool(list)', function (obj) {
					var data = obj.data;
					var id = data.ad_postion_id;
					if (obj.event === 'del') {
						var uri="{:url(SYS_PATH.'/'.CONTROLLER.'/doDelete')}"
						layui.doDelete(uri,"确定要删除吗？",id,obj);//单个删除接口
					}else if (obj.event === 'edit') {
						layui.layerOpen("{:url(SYS_PATH.'/'.CONTROLLER.'/edit')}?id="+id,data.title);
					}
				});					
						
			
	});
</script>
</body>
</html>